/*
XPTracker - Alternative Agile Tracking Tool
Copyright (C) 2006-2009  Stephen Starkey

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/
package org.xptracker.search;

import junit.framework.TestCase;
import org.apache.lucene.document.Document;
import org.xptracker.domain.*;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author caliendo
 */
public class AbstractIndexingHelperTest extends TestCase {

  private static final AbstractIndexingHelper helper = new AbstractIndexingHelper() {
    public Document buildDocument(Object obj) throws RuntimeException { return null; }
    public List<String> loadQueryFields(Class clazz) throws RuntimeException { return null; }
    public List<SearchHelp> loadHelpBeans(Class clazz) { return null; }
    public String getIdField(Class clazz) { return null; }
    public String getId(Object obj) { return null; }
  };

  private User user() { 
    final User user = new User("username");

    user.setFullName("fullName");
    user.setEmail("email");
    return user;
  }

  private void assertStringValue(final String expectedValue, final Object obj) {
    assertEquals("expected stringValue to be a certain value [" + (obj != null ? obj.getClass() : null) + "]", expectedValue, helper.stringValue(obj));
  }

  // -----
  // tests
  // -----

  public void testStringValue() throws Exception {
    assertStringValue("string", "string");
    assertStringValue("", null);
    assertStringValue("username fullName email", user());
    assertStringValue(new SimpleDateFormat(AbstractIndexingHelper.DATE_PATTERN).format(new Date(0)), new Date(0));
    assertStringValue("storyCategory", new StoryCategory("storyCategory"));
    assertStringValue("customer", new Customer("customer"));
    assertStringValue("username fullName email", new EffortEntry(new Story(), user(), new Date(0), new Date(0), ""));
    assertStringValue("task task username fullName email", new Task("task", "task", user()));
    assertStringValue("blogEntry username fullName email", new BlogEntry(user(), new Story(), "blogEntry"));
    assertStringValue("collectionString collectionBuilder username fullName email", Arrays.asList(new Object[]{"collectionString", new StringBuilder("collectionBuilder"), user()}));
    assertStringValue("task task ", new Task("task", "task", null));
  }

}
